<template>
  <div class="app-content-wrap" :style="'minHeight:' + gHeight + 'px;'">
    <div class="g-content-title">
      访客管理
    </div>
    <!-- 搜索框 -->
    <el-form :model="userFilter" label-width="100px" size="small">
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="社区">
            <AreaSelect :selectModel="userFilter.deptId" :areaIds="areaIds" @onAreaChange="onAreaChange" hideThird="true">
            </AreaSelect>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="状态">
            <el-select v-model="userFilter.proveState" placeholder="选择状态">
              <el-option v-for="item in subTypeArr" :key="item.value" :value="item.value" :label="item.name">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="被访人姓名">
            <el-input v-model="userFilter.userName" placeholder="姓名"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="被访人电话">
            <el-input v-model="userFilter.mobile" placeholder="电话"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item>
            <el-button type="primary" size="small" icon="el-icon-search" @click="getUserFromFilter">搜 索</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <!-- 列表 -->
    <div style="margin:10px 30px;">
      <el-table :data="userListTable" border style="width: 100%">
        <el-table-column prop="interviewNum" label="访客单号" min-width="150" align="center"></el-table-column>
        <el-table-column :formatter="visitorStatusToText" label="状态" min-width="100" align="center"></el-table-column>
        <el-table-column label="访客信息" min-width="150">
          <template slot-scope="scope">
            <div>
              <p>姓名：{{scope.row.visitorName}}</p>
              <p>手机：{{scope.row.visitorMobile}}</p>
              <p>随行人数：{{scope.row.visitorNumber}}人</p>
              <p>拜访事由：{{scope.row.content}}</p>
              <p>拜访开始时间：{{scope.row.visitorBeginTime}}</p>
              <p>拜访截止时间：{{scope.row.visitorEndTime}}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="被访人信息" min-width="140">
          <template slot-scope="scope">
            <div>
              <p>姓名：{{scope.row.interviewName}}</p>
              <p>手机：{{scope.row.interviewMobile}}</p>
              <p>地址：{{scope.row.interviewAddr}}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="提交时间" min-width="140" align="center"></el-table-column>
        <el-table-column prop="checkTime" label="审核时间" min-width="140" align="center"></el-table-column>
        <!-- <el-table-column label="扫码记录" width="190" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="viewLog(scope.row)">查看</el-button>
          </template>
        </el-table-column> -->
      </el-table>

      <el-pagination background @current-change="handleCurrentChange" :current-page.sync="pagination.currentPage" :page-size="10" layout="total, prev, pager, next,jumper" :total="pagination.total" class="el-page-body"></el-pagination>
    </div>
  </div>
</template>
<script>
import AreaSelect from '../../components/common/select/area.vue'
// import areaSelect from '../../components/common/select/area'
// import SelectRole from '../../components/common/select/role.vue'

export default {
  name: 'userInfo',
  components: {
    AreaSelect
  },
  data () {
    return {
      gHeight: this.$store.state.gHeight,
      subTypeArr: [],
      userFilter: {
        userName: '', // 姓名
        mobile: '', // 电话
        deptId: '', // 部门
        proveState: '' // 申请状态
      },
      areaIds: {
        areaId1: '', // 所属1级
        areaId2: '', // 所属2级
        areaId3: '' // 所属3级
      },
      userListTable: [],
      pagination: {
        currentPage: 1,
        total: null
      }
    }
  },
  methods: {
    getUserFromFilter: function () { /// /表单
      this.pagination.currentPage = 1
      this.getUser()
    },
    handleCurrentChange (val) {
      this.pagination.currentPage = val
      this.getUser()
    },
    getUser () {
      const url = this.$base.getUrl('bizvisitorinfoSearch')
      let params = {
        isJson: true,
        url: url,
        data: {
          visitorName: this.userFilter.userName, // 姓名
          visitorMobile: this.userFilter.mobile, // 电话
          deptId: this.userFilter.deptId, // 小区
          status: this.userFilter.proveState,
          page: this.pagination.currentPage,
          limit: 10
        }
      }
      this.$store.dispatch('postForm', params).then((res) => {
        let { result } = res
        this.userListTable = result.list
        this.pagination.currentPage = result.currPage
        this.pagination.total = result.totalCount
      })
    },
    // role组件change时
    onRoleChange (val) {
      this.userFilter.role = val
    },
    // 所属变化时
    onAreaChange (val) {
      this.userFilter.deptId = val
    },
    // 状态转文字
    visitorStatusToText (row) {
      return this.$base.getNameByConst('select', 'visitorStatus', parseInt(row.status))
    }
  },
  mounted () {
    this.subTypeArr = this.$base.getConst('select', 'visitorStatus')
    this.getUser()
  }
}
</script>
<style scoped>
.el-table {
  width: auto !important;
  text-align: center;
  margin: 10px;
}

.el-table >>> th {
  text-align: center;
}
</style>
